
import { getAuthCache, setAuthCache } from '@/utils/auth';
import { defineStore } from 'pinia';
import { store } from '@/store';
import { USER_LANGUAGE_KEY } from '@/enums/cacheEnum';
interface CommonState {
  isLoading: boolean;
  language: string;
}

export const useCommonStore = defineStore({
  id: 'app-common',
  state: (): CommonState => ({
    isLoading: false,   //弹层loding
    language: 'zh_CN',     //国际化
  }),
  getters: {
    getIsLoading():any {
      return this.isLoading;
    },
    getLanguage():any {
      return this.language;
    },
  },
  actions: {
    setIsLoading(state:boolean = false) {
      this.isLoading = state; 
    },
    setLanguage(info:string) {
      this.language = info; 
      setAuthCache(USER_LANGUAGE_KEY, info);
    },
  }
});

//需要在设置之外使用
export function useCommonStoreWithOut() {
  return useCommonStore(store);
}


//使用实例
// import { useCommonStoreWithOut } from '@/store/modules/common';
// const commonStore = useCommonStoreWithOut();